<!--_meta 作为公共模版分离出去-->
<#include "include/_meta.html">
<!--/meta 作为公共模版分离出去-->
<style type="text/css">
.pageleft{
width:450px;
float:left;

}

.pageright{
width:350px;
height:400px;
float:right;

}


.pagebottom{
margin:50px auto;
width:1100px;
clear:both;

}

</style>
	<link rel="stylesheet" href="lib/zTree/v3/css/demo.css" type="text/css">
	<link rel="stylesheet" href="lib/zTree/v3/css/zTreeStyle/zTreeStyle.css" type="text/css">
	
	


<title>角色管理 - 添加角色</title>
<meta name="keywords" content="汽车租赁">
<meta name="description" content="H-ui.admin v2.3，是一款由国人开发的轻量级扁平化网站后台模板，完全免费开源的网站后台管理系统模版，适合中小型CMS后台系统。">
</head>
<body>
<article class="page-container">
	<form class="form form-horizontal" id="form-admin-add" >
<div class="pageleft">
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色名称：</label>
		<div class="formControls col-xs-8 col-sm-9">
			<input type="text" class="input-text" value="${(role.roleName)!''}" placeholder="" id="roleName" name="roleName">
		</div>
	</div>
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色编码:</label>
		<div class="formControls col-xs-8 col-sm-9">
			<input type="text" class="input-text" value="${(role.roleId)!''}" placeholder="" id="roleId" name="roleId" readOnly>
		</div>
	</div>
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>是否启用:</label>
		<div class="formControls col-xs-8 col-sm-9 skin-minimal">
			<div class="radio-box">
			<#if "${(role.isabled)!''}"=='1'>
				<input name="isabled" type="radio" value="1" id="isabled-1" checked>
			<#else>
				<input name="isabled" type="radio" value="1" id="isabled-1" >
			</#if>
				<label for="isabled-1">是</label>
			</div>
			<div class="radio-box">
			<#if "${(role.isabled)!''}"=='0'>
				<input name="isabled" type="radio" value="0" id="isabled-2" checked>
			<#else>
				<input name="isabled" type="radio" value="0" id="isabled-2" >
			</#if>
				<label for="isabled-2">否</label>
			</div>
		</div>
	</div>
	
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3">角色描述</label>
		<div class="formControls col-xs-8 col-sm-9">
			<textarea id="describe" name="" cols="" rows="" class="textarea" placeholder="" drogonfly="true" onKeyUp="textarealength(this,100)">${(role.discribe)!''}</textarea>
			<p class="textarea-numberbar"><em class="textarea-length">0</em>/100</p>
			
		</div>
	</div>
	
</div> 
<div class="pageright">
	<div class="zTreeDemoBackground left">
		<ul id="treeDemo" class="ztree"></ul>
	</div>
</div>
<div class="pagebottom">
	<div class="row">
		<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
			<input class="btn btn-primary radius" type="button" value="&nbsp;&nbsp;提交&nbsp;&nbsp;" onclick="$('#form-admin-add').submit()"/>
		</div>
	</div>
</div>
	</form>
</article>

<!--_footer 作为公共模版分离出去--> 
<#include "include/_footer.html">
<!--/_footer /作为公共模版分离出去--> 


<!--请在下方写此页面业务相关的脚本--> 
<script type="text/javascript">
	



$(function(){

	var setting = {
			check: {
				enable: true
			},
			data: {
				simpleData: {
					enable: true
				}
			},
			async: {
				enable: true,
				url:"resource/listbyid",
				autoParam:["id"],
				otherParam:{"roleid":"${(role.roleId)!''}"},
			}
			
		};
		

		$(document).ready(function(){
			$.fn.zTree.init($("#treeDemo"), setting);
		});
		
		
		function getCheckedNodes(){
				var checkedPermisId='';
				var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
				nodes = zTree.getCheckedNodes();
				if(nodes.length==0){
					alert("请至少选择一项资源");
					return ;
				}
				for(var i=0, l=nodes.length; i<l; i++){
					checkedPermisId += nodes[i].id+",";
				}
				return checkedPermisId;
		}
		
			
		

	
	$("#form-admin-add").validate({
		rules:{
			roleName:{
				required:true
				},
			roleId:{
				required:true
				}
			
		},
		messages:{
			roleName:{
			 required:"请输入角色名称",
			 remote:"角色名称已存在，请重新输入"
			},
			roleId:{
			 required:"请输入角色编号",
			 remote:"角色编号已存在，请重新输入",
			 number:true,
			 digits:true
			}
		},
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
			var permisIds=getCheckedNodes();
	   		$.ajax({
	            type: 'post', 
				contentType:"application/json", 
	            url: '/role/edit', 
	            data:JSON.stringify({
						'roleName': $("#roleName").val(),
		                'roleId': $("#roleId").val(),
		                'discribe': $("#describe").val(),
						'isabled':$(":radio:checked").val(),
		                'permisIds': permisIds
						}),
						
	            success:function(data){ 
	 				console.log('提交成功！');
	 				var index = parent.layer.getFrameIndex(window.name);
					parent.location.reload();
					parent.layer.close(index);
	            }
	
	        });

			
		}
		
	});
});
</script> 

<!--/zTree例子-->
<SCRIPT type="text/javascript">
		
	
		
		
	</SCRIPT>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>